package org.apache.catalina.util;

import java.util.*;

/**
 * @packgeName: ex03.connector.http
 * @ClassName: ParameterMap
 * @copyright: CopyLeft
 * @description:<描述>
 * @author: lili
 * @date: 2017/8/11-18:06
 * @version: 1.0
 * @since: JDK 1.8
 */
public final class ParameterMap extends HashMap {

    public ParameterMap(){
        super();
    }

    public ParameterMap(int initialCapacity){
        super(initialCapacity);
    }

    public ParameterMap(int initialCapacity, float loadFactor){
        super(initialCapacity,loadFactor);
    }

    public ParameterMap(Map map){
        super(map);
    }

    //并发锁，同步锁
    private boolean locked = false;

    public boolean isLocked(){
        return this.locked;
    }

    public void setLocked(boolean locked) {
        this.locked = locked;
    }

    private static final StringManager sm =  StringManager.getManager("org.apache.catalina.util");

    public void clear(){
        if(locked){
            throw new IllegalStateException(sm.getString("parameterMap.locked"));
        }
        super.clear();
    }

    public Object put(Object key,Object value){
        if(locked){
            throw new IllegalStateException(sm.getString("parameterMap.locked"));
        }
        return super.put(key,value);
    }

    public void putAll(Map map){
        if(locked){
            throw new IllegalStateException(sm.getString("parameterMap.locked"));
        }
        super.putAll(map);
    }

    public Object remove(Object key){
        if(locked){
            throw new IllegalStateException(sm.getString("parameterMap.locked"));
        }
        return super.remove(key);
    }
}
